﻿using System;
using Telerik.Web.UI;
using System.Data;

namespace EXAM.Admin.Page_Admin
{
    public partial class TestLog : System.Web.UI.Page
    {
        string sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtID.Text = Session["TestID"].ToString();
                Session["TestID"] = null;



            }
        }

        protected void dgvList_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            BUS.Test_LogControl logCtr = new BUS.Test_LogControl();
            if (cboUser.SelectedValue != null && cboUser.SelectedValue != "")
            {
                int createF = BUS.CommonControl.ConvertDateToInt(dpCreateF.SelectedDate);
                int createT = BUS.CommonControl.ConvertDateToInt(dpCreateT.SelectedDate);
                DataTable dt = logCtr.GetByUser(Convert.ToInt64(txtID.Text), Convert.ToInt64(cboUser.SelectedValue), createF, createT, ref sErr);
                dgvList.DataSource = dt;
            }
        }

        protected void dgvList_ItemCommand(object sender, GridCommandEventArgs e)
        {

        }

        protected void cboUser_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            BUS.UserControl usrCtr = new BUS.UserControl();
            DataTable dt = usrCtr.GetAll_User(ref sErr);
            foreach (DataRow dataRow in dt.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();

                item.Text = (string)dataRow["Username"];
                item.Value = dataRow["ID"].ToString();

                string firstName = (string)dataRow["Firstname"];
                string lastname = (string)dataRow["Lastname"];

                item.Attributes.Add("Firstname", firstName.ToString());
                item.Attributes.Add("Lastname", lastname.ToString());

                //item.Value += ":" + unitPrice;

                cboUser.Items.Add(item);
                item.DataBind();

            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            dgvList.Rebind();
        }


    }
}
